package com.robert.demo.controller;

import com.robert.common.commonutil.bean.vo.ResultData;
import com.robert.demo.common.utils.PostLogHandler;
import com.robert.demo.entity.OptLogInfo;
import com.robert.demo.service.IOptLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * controller:
 *
 * @author zhaoshengtao
 * @date 2024/03/11
 */
@RestController
@Slf4j
public class DemoController {

    @Autowired
    private IOptLogService optLogService;

    @GetMapping("/")
    public String index(){
        return "hello, welcome to spring boot demo 3.x";
    }

    @GetMapping("/log")
    public ResultData getLog(){
        String start = PostLogHandler.start("测试接口", "http://localhost:8001/log","1", 1,
                  "这是一个测试");
        try {
            ResultData success = ResultData.success(start);
            PostLogHandler.end(success.toString());
            return success;
        }catch (Exception e){
            PostLogHandler.exception(e, "请求失败");
        }
        return null;
    }

    @GetMapping("/query")
    public ResultData queryList(){
        return optLogService.queryList(OptLogInfo.builder().userId(1).build());
    }
}
